/**
 * 
 */
package org.tio.sitexxx.web.server.utils;

import java.util.Date;

import org.tio.http.common.HttpConst;
import org.tio.http.common.HttpRequest;
import org.tio.sitexxx.service.model.stat.TioIpPullblackLog;
import org.tio.sitexxx.service.service.base.IpInfoService;
import org.tio.sitexxx.service.service.base.TioIpPullblackLogService;

/**
 * @author tanyaowu
 *
 */
public class TioIpPullblackUtils {

	/**
	 * 
	 */
	public TioIpPullblackUtils() {
	}

	public static void addToBlack(HttpRequest request, String remark, byte type) {
		Integer currId = WebUtils.currUserId(request);

		String ip = request.getClientIp();

		TioIpPullblackLog tioIpPullblackLog = new TioIpPullblackLog();
		tioIpPullblackLog.setIp(ip);
		tioIpPullblackLog.setIpid(IpInfoService.ME.save(request.getClientIp()).getId());
		tioIpPullblackLog.setRemark(remark);
		tioIpPullblackLog.setServer(org.tio.sitexxx.service.vo.Const.SERVICE_HOST);
		tioIpPullblackLog.setServerport(request.getChannelContext().getServerNode().getPort());
		tioIpPullblackLog.setTime(new Date());
		tioIpPullblackLog.setType(type);

		tioIpPullblackLog.setSessionid(request.getHttpSession().getId());
		tioIpPullblackLog.setCookie(request.getHeader(HttpConst.RequestHeaderKey.Cookie));
		tioIpPullblackLog.setInitpath(request.requestLine.getInitPath());
		tioIpPullblackLog.setPath(request.requestLine.getPath());
		tioIpPullblackLog.setRequestline(request.requestLine.toString());
		tioIpPullblackLog.setUid(currId);

		TioIpPullblackLogService.ME.addToBlack(tioIpPullblackLog);

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}
